$().ready(function() {
	validateRule();
	$.ajax({
		cache : true,
		type : "get",
		url : "/jzApi/examinations/selExaminationCom",
		data:{
			type: sessionStorage.getItem('types')
		},
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {

			if (data.code == 0) {

				$('#cbatchId').selectPage({
					showField: 'name',
					keyField: 'id',
					data: data.data,
					eAjaxSuccess : function(d){
						var result;
						if(d) result = d.data;
						else result = undefined;
						return result;
					},
					eSelect : function(data){
						$('#cbatchId').val(data.id);
					}
				});

			} else {
				parent.layer.alert(data.msg)
			}
		}
	});
});

$.validator.setDefaults({
	submitHandler : function() {
		update();
	}
});

function update() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/jzweb/stuSignUpCom/update",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			},
			idNumber : {
				required : true
			},
			ticketNumber : {
				required : true
			},
			cbatchId : {
				required : true
			},
			competitionType : {
				required : true
			},
			unitName : {
				required : true
			}
		},
		messages : {
			name : {
				required : icon + "请输入姓名"
			},
			idNumber : {
				required : icon + "请输入身份证号码"
			},
			ticketNumber : {
				required : icon + "请输入联系方式"
			},
			cbatchId : {
				required : icon + "请选择所属竞赛"
			},
			competitionType : {
				required : icon + "请选择竞赛类型"
			},
			unitName : {
				required : icon + "请输入参赛单位"
			}
		}
	})
}

